﻿using System.Diagnostics;

namespace DynamicProxyCore
{
	[DebuggerDisplay("GetHashCode()")]
	public class ComposedKey
	{
		private readonly int _hashCode = 337;

		public ComposedKey(params object[] keys)
		{
			foreach (var key in keys)
			{
				_hashCode ^= key.GetHashCode();
			}
		}

		private bool Equals(ComposedKey other)
		{
			return other._hashCode == _hashCode;
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj)) return false;
			if (ReferenceEquals(this, obj)) return true;
			if (obj.GetType() != typeof(ComposedKey)) return false;
			return Equals((ComposedKey)obj);
		}

		public override int GetHashCode()
		{
			return _hashCode;
		}

		public static bool operator ==(ComposedKey left, ComposedKey right)
		{
			return Equals(left, right);
		}

		public static bool operator !=(ComposedKey left, ComposedKey right)
		{
			return !Equals(left, right);
		}
	}
}